/*
 * File:   Schwefel2_22.h
 * Author: jcrada
 *
 * Created on 23 July 2011, 1:19 PM
 */

#ifndef ECB_SCHWEFEL2_22_H
#define	ECB_SCHWEFEL2_22_H

#include "ecb/base/Problem.h"
#include <cmath>
namespace ecb {

    /* Source:
   @book{bf:qings-book,
        author = {Qing, Anyong},
        title = {Differential Evolution: Fundamentals and Applications in Electrical Engineering},
        year = {2009},
        publisher = {Wiley-IEEE Press}}
     */
    class Schwefel2_22 : public Problem {
    public:

        Schwefel2_22(const std::string& id = "Schwefel2_22", const std::string& name = "Schwefel2_22",
                int dimensions = 0, scalar minimum = -100, scalar maximum = 100,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }

        scalar f(const std::vector<scalar>& x) {
            scalar sum = 0, prod = 1;
            for (size_t i = 0; i < x.size(); ++i) {
                sum += std::fabs(x[i]);
                prod *= std::fabs(x[i]);
            }

            return sum + prod;
        }
    };

}

#endif	/* ECB_SCHWEFEL2_22_H */

